<?php
namespace app\servercomment\logic;

use \app\manage\logic\BaseLogic;

/**
 * @author:      李颖
 * @DateTime:    2017-06-13 14:15:09
 * @Description: 用户评论
 */
class CommentReply extends BaseLogic
{
	protected $name = 'comment_reply';
    protected $config = 'db_config_comment';
    protected $commentReplyModel = 'app\servercomment\model\CommentReply';
    protected $searchWhere = ['comment_id'=>'in'];

    /*A用户回复B用户对某文章的评论*/
 	public function replyComment($data): array 
 	{
 		$res = $this->model($this->commentReplyModel)->save($data);
 		return auto_return($res);
 	}

 	/*db获取某一回复的详情*/
 	public function dbReplyInfo($data)
 	{
 		$_where['id'] = $data['id'];
 		$_where['status'] = 1;
 		return $this->db()->where($_where)->find();
 	}

 	/*db获取所有所有回复内容*/
 	public function dbReplys($map = [])
 	{
 		$res = [];
 		is_numeric($map['comment_id']) && $map['comment_id'] = [$map['comment_id']];
 		$_where = $this->searchWhere($map, $this->searchWhere);
 		$_where['status'] = 1;
 		$res = $this->db()->where($_where)->select();
 		if($res){
 			$res = list_to_tree($res,'id','reply_id','_child');
        	$res = reset_array_key($res, 'comment_id', false);
 		}
 		return $res;
 	}



}